#include "MainHeader.h"


	clsScrollBar::~clsScrollBar(){}
	clsScrollBar::clsScrollBar(){}
int clsScrollBar::MakeMe(int Type, HWND Parent, int resource ){

    me = GetDlgItem(Parent, resource);
	scrlType=Type; 



    return GetLastError();

}
int clsScrollBar::resize(int X, int Y, int Width, int Height){
 return  MoveWindow(me, X, Y, Width, Height,0);
} 

int clsScrollBar::Change(){

	SCROLLINFO		inf;
	memset(&inf,0,sizeof(SCROLLINFO));		// zero out our SCROLLINFO struct
	inf.cbSize = sizeof(SCROLLINFO);		// cbSize must be the size of the struct (weird WinAPI nonsense)

	// now we start filling our scroll struct with relevent info.
	//   start with H Scroll whynot

	// fMask determines the properties of this scrollbar we'll be changing.
	// Combine values with OR
	inf.fMask =		SIF_DISABLENOSCROLL |	// This makes it so the scrollbar is disabled when unnecesary
											// otherwise it's hidden (this is usually more applicable to scrollbars
											// that are attached to normal windows -- not so much for scrollbar
											// controls on dialogs -- but whatever)
					SIF_PAGE |				// we will be updating the 'nPage' value
					SIF_POS |				// and the 'nPos' value
					SIF_RANGE;				// and min/max values

	// I'm unsure how this works exactly.  It affects the size
							// of the scrollable part of the bar, but I'm unclear on details.
							// higher values mean fatter bar.  Let's just use 1 because it's simple

	inf.nPos =		0;		// reset position to 0

	inf.nMin =		0;		// minimum H scroll is 0

	

	// now that the SCROLLINFO struct is filled, set the properties of the scrollbar
	if(scrlType==SBS_HORZ){
			// maximum H scroll
     
		inf.nMax =	maxscroll;
		
			
          	SetScrollInfo(	me,		// HWND to scrollbar
					SB_CTL,					// this scrollbar is a dialog control
					&inf,					// pointer to our info struct
					1 );
			// redraw flag (redraw the scrollbar after this change)
		
		inf.nPage =	 0;	
	
	}else{

	// V Scroll is the same thing.  All values in the struct remain the same except for the max

		inf.nMax =		maxscroll;

		

        SetScrollInfo(	me,
					SB_CTL,
					&inf,
					1 );
		inf.nPage =	0;	

	
	}

	  SetScrollRange( me, SB_CTL, 0, maxscroll, FALSE);

    // SetScrollPos( me, scrlType, 0, 1 );
	 
  return GetLastError();
	
}
void clsScrollBar::UpdateScroll(WPARAM how)
{
	
/*
	 *	Called whenever the user scrolls (called by WM_HSCROLL and WM_VSCROLL)
	 *
	 *    dialogwnd is the HWND to the dialog
	 *    how is the WPARAM passed to WM_HSCROLL or WM_VSCROLL (it contains info about the scroll)
	 *    isvertical is 0 for H scrolling, 1 for V scrolling
	 */

	// I usually do tricks with pointers and LUTs and stuff here to recycle a lot of code
	//   so I don't have to have if/else chains everywhere, but that might make this confusing
	//   so I'll stick to more basic practices:



	// find out how the user is scrolling
	//  admittedly, this is a royal pain in the arse

	SCROLLINFO		inf;
	memset(&inf,0,sizeof(SCROLLINFO));		// zero out our SCROLLINFO struct
	inf.cbSize = sizeof(SCROLLINFO);		// cbSize must be the size of the struct (weird WinAPI nonsense)

	// now we start filling our scroll struct with relevent info.
	//   start with H Scroll whynot

	// fMask determines the properties of this scrollbar we'll be changing.
	// Combine values with OR
	inf.fMask =		SIF_DISABLENOSCROLL |	// This makes it so the scrollbar is disabled when unnecesary
											// otherwise it's hidden (this is usually more applicable to scrollbars
											// that are attached to normal windows -- not so much for scrollbar
											// controls on dialogs -- but whatever)
					SIF_PAGE |				// we will be updating the 'nPage' value
					SIF_POS |				// and the 'nPos' value
					SIF_RANGE;				// and min/max values

	// I'm unsure how this works exactly.  It affects the size
							// of the scrollable part of the bar, but I'm unclear on details.
							// higher values mean fatter bar.  Let's just use 1 because it's simple

	inf.nPos =		0;		// reset position to 0

	inf.nMin =		0;		// minimum H scroll is 0

	int cowpie=0;
	switch(LOWORD(how))
	{
	case SB_LEFT:	curscroll = 0;			break;	// scroll all the way to the left
	case SB_RIGHT:	curscroll = maxscroll;	break;	// all the way to the right
	case SB_LINELEFT: curscroll -= 1;		break;	// one click to the left
	case SB_LINERIGHT: curscroll += 1;		break;	// one click to the right
	case SB_PAGELEFT: curscroll -= 10;		break;	// one page to the left
	case SB_PAGERIGHT: curscroll += 10;		break;	// one page to the right
	case SB_THUMBTRACK: curscroll = HIWORD(how); break;	// user is dragging bar
	}

	// keep scroll within bounds
	if(curscroll > maxscroll)	curscroll = maxscroll;
	if(curscroll < 0)			curscroll = 0;

	// update our scroll vars, as well as the scrollbar itself
//	if(scrlType==SBS_VERT)
//	{
		
		inf.nMax =		maxscroll;
		inf.nPos =		curscroll;		// reset position to 0

		inf.nMin =		0;		// minimum H scroll is 0

		

        SetScrollInfo(	me,
					SB_CTL,
					&inf,
					1 );
		inf.nPage =	0;	
		SetScrollRange( me, SB_CTL, 0, maxscroll, FALSE);
        SetScrollPos(me,SB_CTL,curscroll,1);
	
}


int clsScrollBar::ResizeScrollBar(int Min, int Max){
   
	;
	memset(&inf,0,sizeof(SCROLLINFO));		// zero out our SCROLLINFO struct
	inf.cbSize = sizeof(SCROLLINFO);		// cbSize must be the size of the struct (weird WinAPI nonsense)

	// now we start filling our scroll struct with relevent info.
	//   start with H Scroll whynot

	// fMask determines the properties of this scrollbar we'll be changing.
	// Combine values with OR
	inf.fMask =		SIF_DISABLENOSCROLL |	// This makes it so the scrollbar is disabled when unnecesary
											// otherwise it's hidden (this is usually more applicable to scrollbars
											// that are attached to normal windows -- not so much for scrollbar
											// controls on dialogs -- but whatever)
					SIF_PAGE |				// we will be updating the 'nPage' value
					SIF_POS |				// and the 'nPos' value
					SIF_RANGE;				// and min/max values

	inf.nPage =		0;		// I'm unsure how this works exactly.  It affects the size
							// of the scrollable part of the bar, but I'm unclear on details.
							// higher values mean fatter bar.  Let's just use 1 because it's simple

	inf.nPos =		curscroll;		// reset position to 0

	inf.nMin =		Min;		// minimum H scroll is 0

	return 0;
}